<admintpl file="header" />
</head>
<body>
<div class="wrap">
	<form class="well form-search" method="post" action="{:U('UserBindCom/bind',array('user_id'=>I('request.user_id/s','')))}">
		企业名称：
		<input type="text" name="com_name" style="width: 100px;" value="{:I('request.com_name/s','')}" placeholder="请输入企业名称">
		地区:
		<admintpl file="city" />
		<input type="submit" class="btn btn-primary" value="搜索" />
		<a class="btn btn-danger" href="{:U('UserBindCom/bind',array('user_id'=>I('request.user_id/s','')))}">清空</a>
	</form>
	<form method="post" class="js-ajax-form">
		<table class="table table-hover table-bordered">
			<thead>
			<tr>
				<th align="center">ID</th>
				<th>企业名称</th>
				<th>企业地址</th>
				<th>所属行业</th>
				<th>企业规模</th>
				<th>创建时间</th>
				<th align="center">绑定</th>
			</tr>
			</thead>
			<tbody>
			<foreach name="list" item="vo">
				<tr>
					<td align="center">{$vo.id}</td>
					<td>{$vo.com_name}</td>
					<td>
						{:F('cache_city')[$vo['province']]['name']}
						{:F('cache_city')[$vo['city']]['name']}
						{:F('cache_city')[$vo['district']]['name']}
					</td>
					<td>
						{:C('COM_SSHT')[$vo['trade']]['dict_text']}
					</td>
					<td>{:C('COM_GM')[$vo['scale']]['dict_text']}</td>
					<td>{$vo.created_time|date="Y-m-d",###}</td>
					<td align="center">
						<empty name="vo.is_bind">
							<input type="checkbox" class="bind-checkbox" is_bind="{$vo.is_bind}" state="2" bind_id="{$vo.bind_id}" com_id="{$vo.id}">
							<else />
							<input type="checkbox" class="bind-checkbox" state="1" bind_id="{$vo.bind_id}" com_id="{$vo.id}"  checked>
						</empty>
					</td>
				</tr>
			</foreach>
			</tbody>
		</table>
		<div class="pagination">{$page}</div>
	</form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript">
	$(function(){
		$('.bind-checkbox').click(function(){
		    var $this = $(this);
		    var bind_id = $this.attr('bind_id');
		    var com_id = $this.attr('com_id');
		    var state = $this.attr('state');
            $this.attr('disabled',true);
            $.ajax({
                type: "POST",
                dataType:"json",
                url: "{:U('UserBindCom/bind_ajax',array('user_id'=>I('request.user_id/s','')))}",
                data: {
                    "bind_id":bind_id,
                    "com_id":com_id,
                    "state":state
                },
                success: function(data){
					if(data['state_code']==1){
                        artdialog_ok_alert(data['msg']);
                        $this.attr('state',data['bind_state']);
                        if(data['bind_state']==1){
                            $this.attr('bind_id',data['bind_id']);
						}
					}else{
                        artdialog_alert(data['msg']);
                        $this.attr('checked',!$this.attr('checked'));
					}
                    $this.attr('disabled',false);
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    artdialog_alert('操作错误请重试');
                    $this.attr('checked',!$this.attr('checked'));
                    console.info(XMLHttpRequest);
                    console.info(textStatus);
                    console.info(errorThrown);
                }
            });
		});
	});
</script>
</body>
</html>